﻿using System;
using System.Windows.Threading;

namespace Twilight.TwitterData
{
    public abstract class BaseDataProvider
    {
        private DispatcherTimer timer;

        public event EventHandler<TweetsUpdatedEventArgs> TweetsUpdated;

        public string Username { get; set; }
        public string Count { get; set; }

        public static BaseDataProvider Instance { get; private set; }

        public BaseDataProvider()
        {
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(60);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        protected void OnTweetsUpdated(Tweet[] tweets)
        {
            if (TweetsUpdated != null)
            {
                TweetsUpdated(this, new TweetsUpdatedEventArgs() { Tweets = tweets });
            }
        }

        public virtual void Initialize(string username, string count)
        {
            Instance = this;
            Username = username;
            Count = count;
        }

        protected abstract void timer_Tick(object sender, EventArgs e);
    }

    public class TweetsUpdatedEventArgs : EventArgs
    {
        public Tweet[] Tweets { get; set; }
    }
}
